<?php
    //the "mainaction" use to deal with the POST information of homepage or link orders
    class mainaction{
        private static function getdmt(){
            $y=date("Y",time());
            $m=date("m",time());
            $d=date("d",time());
            $t0=date('t');           // 本月一共有几天
            $t1=mktime(0,0,0,$m,1,$y);        // 创建本月开始时间
            $t2=mktime(23,59,59,$m,$t0,$y);       // 创建本月结束时间
            $rdate['today'] = date("Y-m-d",time());
            $rdate['dmtb'] = date("Y-m-d H:i:s",$t1);
            $rdate['dmte'] = date("Y-m-d H:i:s",$t2);
            $rdate['sjc'] = $t2-$t1;
            return $rdate;
        }
        public static function getleftnavfloder(){
            $xml = file_get_contents('./tpl/tpl.lnf.html');
            return $xml;
        }
        public static function getckbifm(){
            $xml = file_get_contents('./tpl/tpl.ckbifm.html');
            return $xml;
        }
        public static function gettoptpl(){
            $xml = file_get_contents('./tpl/tpl.top.html');
            return $xml;
        }
        public static function trtabname($index){
            $index_name = array(
                1 => '知识库系统',
                2=>'投诉下单系统',
                3=>'工单处理系统',
                4=>'客户实名制系统',		
                5=>'质检系统',
            );
            if (isset($index_name[$index])){
                return $index_name[$index];
            }else {
                return '找不到名称';
            }
        }
        public static function getyclplance($val,$posti){
            switch ($val){
                case 'begin':
                    $rxml = file_get_contents('./tpl/ycl/ycl-begin.tpl');
                    break;
                case 'turn':
                    $rxml = file_get_contents('./tpl/ycl/'.$posti['snp'].'.tpl');
                    break;
            }
            return $rxml;
        }
        public static function searchxiaojie($value=NULL){
            # 查询小结...
            global $db;
            $dmt = self::getdmt();
            $items = array();
            if (isset($value)) {
                $db->ExeQuerySql("SELECT * FROM cu_ckb WHERE czj='$value'");
            }else{
                $db->ExeQuerySql("SELECT * FROM cu_ckb WHERE date >= '$dmt[dmtb]' and date <= '$dmt[dmte]'");
            }
            while ($row = $db->GetFetchArray()) {
                array_push($items, $row);
            }
            $value =array(
                "total" => count($items),
                'rows' => $items
            );
            $nonetr = json_encode($value);
            return $nonetr;
        }
        public static function newtelrec($posti){
            global $db;
            $sql = "INSERT INTO `cu_gongdan`.`cu_ckb` (`date`, `cname`, `czj`, `cnumber`, `stt`, `ste`, `leaght`, `xjlb`, `isend`, `yuanyin`, `dafu`, `ctlman`) VALUES ('$posti[date]', '$posti[cname]', '$posti[czj]', '$posti[cnumber]', '$posti[date]', '', '0', '$posti[xjlb]', '$posti[isend]', '$posti[yuanyin]', '$posti[dafu]', '$posti[ctlman]');";
            $db->ExeSql($sql);
            echo 'success';
        }
}